﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.SqlClient;

namespace EZCRS.HCMS.Bll.baseinfo
{
    public class BllHCRS_HotelLocal
    {
        public List<HCRS_Airport> getallairport(int pid)
        {
            return new sql_hcrs_airport().getallitem(pid);
        }

        public bool modifyairport(HCRS_Airport _airport)
        {
            return new sql_hcrs_airport().insertorupdate(_airport);
        }
        public bool modifytrain(HCRS_Train _train)
        {
            return new sql_hcrs_train().insertorupdate(_train);
        }

        public bool deltrain(int id)
        {
           return new sql_hcrs_train().delitem(id);
        }
        public bool delairport(int id)
        {
            return new sql_hcrs_airport().delitem(id);
        }

        public List<HCRS_Train> getalltrain(int pid)
        {
            return new sql_hcrs_train().getallitem(pid);
        }

        public HCRS_Description getdescription(int pid)
        {
            return new sql_hcrs_description().getitem(pid, 2);
        }

        public HCRS_Hotel gethotel(int hid)
        {
            return new sql_hcrs_hotel().getitem(hid);
        }

        /// <summary>
        /// 获取价格代码对象
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public HCRS_RateCode getRateCode(int ID)
        {
            return new sql_hcrs_ratecode().getRateCodeItem(ID);
        }

        /// <summary>
        /// 判断价格代码是否已存在
        /// </summary>
        /// <param name="RateCode"></param>
        /// <returns></returns>
        public bool RateCodeIsExist(string RateCode, int ID, int PID)
        {
            return new sql_hcrs_ratecode().IsExist(RateCode, ID, PID);
        }

        /// <summary>
        /// 保存价格代码对象
        /// 创建计划代码
        /// </summary>
        /// <param name="rate">价格代码</param>
        /// <param name="roomlist">房间代码列表</param>
        /// <returns></returns>
        public bool SaveRate(HCRS_RateCode rate, Dictionary<string, bool> roomlist, int Language)
        {
            bool b = new sql_hcrs_ratecode().insertorupdate(rate);

            sql_hcrs_Plan plan = new sql_hcrs_Plan();

            if (b)
            {
                foreach (string key in roomlist.Keys)
                {
                    string strPlanCode = key + "-" + rate.RateCode;

                    if (!roomlist[key])
                    {
                        plan.setStatus(rate.Pid, strPlanCode, key, 0, Language);    //未选中则设置为未激活
                    }
                    else
                    {
                        //add or rewrite

                        HCRS_Plan obj = new HCRS_Plan();

                        obj.LanguageType = Language;
                        obj.Pid = rate.Pid;
                        obj.PlanCode = strPlanCode;
                        obj.RoomCode = key;
                        obj.PlanName = rate.Name;

                        plan.Add(obj);

                    }
                }
            }

            return b;
        }

        public bool savedescription(string localtion, string transport, string Longitude, string Latitude, int pid,int desid)
        {
            return new sql_hcrs_description().modifylocal(localtion, transport, Longitude, Latitude, pid,desid);
        }
    }
}
